#!/bin/sh
# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

PRGDIR=`dirname "$PRG"`

# Only set ENTERPRISE_WECHAT_HOME if not already set
[ -z "$ENTERPRISE_WECHAT_HOME" ] && ENTERPRISE_WECHAT_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`

if [ -z "$ENTERPRISE_WECHAT_CONF" ] ; then
  ENTERPRISE_WECHAT_CONF="$ENTERPRISE_WECHAT_HOME"/conf
fi

if [ -z "$_RUNJAVA" ]; then
  _RUNJAVA="$JAVA_HOME"/bin/java
fi

myClassPath="$ENTERPRISE_WECHAT_HOME/lib/*"


myClassPath=$ENTERPRISE_WECHAT_CONF:$myClassPath

if [ -z "$ENTERPRISE_WECHAT_OUT" ] ; then
  ENTERPRISE_WECHAT_OUT="$ENTERPRISE_WECHAT_HOME"/logs/enterprise_wechat_console.log
fi

#shift
mkdir -p "$ENTERPRISE_WECHAT_HOME"/logs


echo "Using              JAVA_HOME: $JAVA_HOME"
echo "Using ENTERPRISE_WECHAT_HOME: $ENTERPRISE_WECHAT_HOME"
echo "Using ENTERPRISE_WECHAT_CONF: $ENTERPRISE_WECHAT_CONF"
echo "Using              CLASSPATH: $myClassPath"

# ===================================================================
# 请根据实际情况注释掉下面两行中的一行
app_profile="prod"
# app_profile="test"

# 如果启动脚本的参数中包含test则认为是测试环境
if [ $# -eq 1 ] && [ $1 = 'test' ]; then
  app_profile="test"
fi


jvm_args_for_prod_env="-Xms2048m -Xmx2048m"
jvm_args_for_test_env="-Xms512m -Xmx512m"

jvm_args=$jvm_args_for_prod_env

if [ -n "$app_profile" ] && [ "$app_profile" = "test" ]; then
  jvm_args=${jvm_args_for_test_env}
elif [ -n "$app_profile" ] && [ "$app_profile" = "prod" ]; then
  jvm_args=${jvm_args_for_prod_env}
fi


echo "           using app_profile: ${app_profile}, jvm_args: ${jvm_args}"

# 如果要绑定某个ip，将如下命令修改ip地址后copy到下面的-D后一行即可
# -Dspring.cloud.inetutils.preferred-networks=10.xx.xx.xx \

eval "\"$_RUNJAVA\"" \
  -Denterprise-wechat \
  -DENTERPRISE_WECHAT_HOME="${ENTERPRISE_WECHAT_HOME}" \
  "${jvm_args}" \
  -classpath "\"$myClassPath\"" \
  io.renren.wechat.WechatServiceApplication "$@" \
  >/dev/null 2>&1 &

echo -e "\nrenren-enterprise-wechat started successfully.\n"








